# coding=utf-8
from json import JSONEncoder
from django.shortcuts import render_to_response
from django.template import RequestContext
from com.kjssoft.rainbow import LOGGER
from com.kjssoft.rainbow.category.models import RainbowPhotoFrameCategory
from com.kjssoft.rainbow.views import response_format_decorator

__author__ = 'Sea'

class RainbowPhotoFrameCategoryJsonEncoder(JSONEncoder):
    def default(self, instance):
        return super(RainbowPhotoFrameCategoryJsonEncoder, self).default(instance)

@response_format_decorator
def list_view_page(request):
    #默认查找第一级的分类
    super_category = request.GET.get('super')
    if not super_category:
        super_category = 'specify'
    rainbow_frame_categories = RainbowPhotoFrameCategory.objects.filter(
        super_category__in = RainbowPhotoFrameCategory.objects.filter(name = super_category)
    )
    LOGGER.debug(type(rainbow_frame_categories[0]))
    has = rainbow_frame_categories[0].has_more
    LOGGER.debug(has)
    return render_to_response(
        'kjs/rainbow/category/list.html',
        {'categories':rainbow_frame_categories},
        context_instance = RequestContext(request)
    )
